#-------------------------------------------------------------------------------
# Project Specific Parameters
#-------------------------------------------------------------------------------

include Make.defines
include @MAKE_DEFINES@

#-------------------------------------------------------------------------------
# Directories
#-------------------------------------------------------------------------------

PREFIX      = @prefix@
DESTDIR     = 
EXEC_PREFIX = @exec_prefix@
BINDIR      = $(DESTDIR)/$(PREFIX)/bin
INCDIR      = $(DESTDIR)/$(PREFIX)/include/
LIBDIR      = $(DESTDIR)/$(PREFIX)/lib/postgresql

INFODIR     = $(DESTDIR)/$(PREFIX)/info
MANDIR      = $(DESTDIR)/$(PREFIX)/man
TOP_SRCDIR  = @top_srcdir@
SRCDIR      = @srcdir@
VERSION     = @VERSION@

#-------------------------------------------------------------------------------
# Compile Options
#-------------------------------------------------------------------------------

CPP         = g++
CC          = gcc
CFLAGS      = -DVERSION=${VERSION} $(ADDCFLAGS) $(INCPATHS) \
              $(PROFILING) $(DEBUGGING) 
CPPFLAGS    = @CPPFLAGS@ $(ADDCPPFLAGS)
LDFLAGS     = @LDFLAGS@  $(ADDLDFLAGS)
LIBS        = @LIBS@     $(ADDLIBS)
INSTALL     = @INSTALL@

#-------------------------------------------------------------------------------
# Targets
#-------------------------------------------------------------------------------

A_LIB       = $(NAME).a
S_LIB       = $(NAME).$(DSO_EXTENSION)
VS_LIB      = $(S_LIB).$(VERSION)
PROGS       = all

LIBFILES    = pgacl.o
FILES       =
HDR         = 

CLEANFILES  = leaks.txt gmon.out prof.txt *core \
	          *.o *~ *.$(DSO_EXTENSION) *.a 

BUILDFILES  = config.h autoscan.log config.status             \
              tmp.txt configure config.log configure.scan

#-------------------------------------------------------------------------------
# Build Programs
#-------------------------------------------------------------------------------

AR			= ar
ARFLAGS		= cru

#-------------------------------------------------------------------------------
# Build
#-------------------------------------------------------------------------------

# Build the library and test program
all:		lib

# Share library (Release)
lib:	lib_preamble $(LIBFILES)
	$(CC) -shared $(LINKFLAGS) -o $(S_LIB) $(LIBFILES) $(LDFLAGS) $(LIBS)

lib_preamble:
	@echo
	@echo "Building PG ACL module"

clean:
	rm -f ${PROGS} ${CLEANFILES} program

distclean: clean
	rm -f ${BUILDFILES}

.cpp.o:
	$(CC) -c $(CPPFLAGS) $(CFLAGS) $<

.c.o:
	$(CC) -c $(CPPFLAGS) $(CFLAGS) $<

#-------------------------------------------------------------------------------
# Install
#-------------------------------------------------------------------------------

USER  = root
GROUP = root

install:
	@echo "Installing module:"
	$(INSTALL) -D -s -m 644 $(S_LIB) $(LIBDIR)/$(S_LIB)

#-------------------------------------------------------------------------------
# Autoconf
#-------------------------------------------------------------------------------

# automatic re-running of configure if the ocnfigure.in file has changed
${SRCDIR}/configure: configure.in
	cd ${SRCDIR} && autoconf

# autoheader might not change config.h.in, so touch a stamp file
${SRCDIR}/config.h.in: stamp-h.in
${SRCDIR}/stamp-h.in: configure.in aclocal.m4
		cd ${SRCDIR} && autoheader
		echo timestamp > ${SRCDIR}/stamp-h.in

config.h: stamp-h

stamp-h: config.h.in config.status
	./config.status

Makefile: Makefile.in config.status
	./config.status

config.status: configure
	./config.status --recheck
